package com.ymatou.query.trading.api.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.query.trading.api.parameter.GetBuyerOrderListBean;
import com.ymatou.query.trading.api.parameter.OrderStatus;
import com.ymatou.query.trading.api.service.GetBuyerOrderListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.common.entitie.OrderInfoForQuery;
import com.ymttest.database.sqlwapper.TradingQueryDefaultWapper;
import com.ymttest.utils.constant.ECode;

/**
 * 根据订单状态查询相关订单信息列表（带分页） FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetBuyerOrderList {

	private static GetBuyerOrderListBean getbuyerorderlistbean;
	private static GetBuyerOrderListCall getbuyerorderlistcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据订单状态查询相关订单信息列表（带分页）");
	}

	@Before
	public void caseUp() {
		getbuyerorderlistbean = new GetBuyerOrderListBean();
		getbuyerorderlistcall = new GetBuyerOrderListCall();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getbuyerorderlistcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderList_001() {
		Logger.start(true,"根据订单状态查询第2页相关订单信息列表（带分页）查询成功");
		try {
			int UserId = 216;
			Logger.comment("UserId:" + UserId);
			getbuyerorderlistbean.setBuyerId(UserId);
			// 当前页码数
			int CurrentPageNum = 2;
			Logger.comment("当前页码:" + CurrentPageNum);
			getbuyerorderlistbean.setCurrentPageNum(CurrentPageNum);
			// 订单状态
			ArrayList<Integer> orderStatus = new ArrayList<Integer>();
			orderStatus.add(4);
			getbuyerorderlistbean.setOrderStatusList(orderStatus);
			// 页面显示记录条数
			getbuyerorderlistbean.setPageSize(5);
			// 发送请求
			getbuyerorderlistcall.setData(getbuyerorderlistbean);
			getbuyerorderlistcall.callService();
			// 查询数据库
			HashMap m = new HashMap();
			int orderStatusUsingMethod = OrderStatus.GetOrderStatusUsingMethod(orderStatus);
			m.put("userId", UserId);
			m.put("tradingStatus", orderStatus);
			m.put("orderStatusUsingMethod", orderStatusUsingMethod);

			List<Map> list = new TradingQueryDefaultWapper().getBuyerOrderList(m);

			Logger.comment("getbuyerorderlistcall send:" + getbuyerorderlistcall.getEntityString());
			Logger.comment("getbuyerorderlistcall response:" + getbuyerorderlistcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getbuyerorderlistcall.getCode(), "验证Code");

			Logger.verifyEquals(list.size(), getbuyerorderlistcall.getAllRecordCount(), "验证所有记录条数");
			ArrayList<OrderInfoForQuery> orderInfo = getbuyerorderlistcall.getOrderInfoList();
			for (int i = 5; i < 9; i++) {
				Logger.debug("iOrderId :" + list.get(i).get("iOrderId"));
				// orderInfo.get(i-5).getOrderId()
				Logger.debug("OrderId :" + orderInfo.get(i - 5).getOrderId());
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetBuyerOrderList_002() {
		Logger.start(true,"根据订单状态查询第1页相关订单信息列表（带分页）查询成功");
		try {
			int UserId = 216;
			Logger.comment("UserId:" + UserId);
			getbuyerorderlistbean.setBuyerId(UserId);
			// 当前页码数
			int CurrentPageNum = 1;
			Logger.comment("当前页码:" + CurrentPageNum);
			getbuyerorderlistbean.setCurrentPageNum(CurrentPageNum);
			// 订单状态
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(4);
			getbuyerorderlistbean.setOrderStatusList(list);
			// 页面显示记录条数
			getbuyerorderlistbean.setPageSize(5);
			// 发送请求
			getbuyerorderlistcall.setData(getbuyerorderlistbean);
			getbuyerorderlistcall.callService();
			ArrayList list1 = getbuyerorderlistcall.getOrderInfoList();
			getbuyerorderlistbean.setCurrentPageNum(2);
			getbuyerorderlistcall.callService();
			ArrayList list2 = getbuyerorderlistcall.getOrderInfoList();
			Logger.comment("判断list是否相等" + list2.equals(list1));
			Logger.verifyEquals(ECode.SUCCESS, getbuyerorderlistcall.getCode(), "验证Code");
			// Logger.verifyEquals(ErrorCode.SUCCESSMSG,
			// getbuyerorderlistcall.getMsg(), "验证Msg");
			Logger.verifyEquals(26, getbuyerorderlistcall.getAllRecordCount(), "验证查询结果列表长度");
			Logger.verifyEquals(true, getbuyerorderlistcall.getAllRecordCount() > 0, "验证所有记录条数");
			Logger.verifyEquals(false, list2.equals(list1), "验证第二页数据与第一页数据是否相等");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}